package message

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/message"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/rpc"
	"github.com/zeromicro/go-zero/core/logc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type NotificationMessageAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 新增通知消息
func NewNotificationMessageAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NotificationMessageAddLogic {
	return &NotificationMessageAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *NotificationMessageAddLogic) NotificationMessageAdd(req *types.AddNotificationMessageReq) (resp *types.Empty, err error) {
	u, err := l.svcCtx.SettingService.Message.NotificationMessageAdd(l.ctx, &message.AddNotificationMessageReq{
		MerchantId: 1,                                     // 商户ID
		Language:   req.Language,                          // 语言
		Type:       rpc.NotificationMessageType(req.Type), // 类型,1:会员注册,2:账号充值,3:申请提现,4:提现到账,5:登录通知,6:XOSO期号取消通知,7:修改密码
		Title:      req.Title,                             // 标题
		Content:    req.Content,                           // 内容
	})

	if err != nil {
		logc.Error(l.ctx, "NotificationMessageAdd err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return nil, code.BusinessFailure
	}

	resp = &types.Empty{}
	return
}
